Central Article

Migrating Your Flash Applications to Macromedia Central


Table of Contents

  1. Introduction
  2. New Features in Macromedia Central
  3. Things to Avoid and Watch Out For
  4. Testing and Debugging Your Application
  5. Enhancing Your Application
  6. Deploying Your Application

Enhancing Your Application

Believe it or not, that's just about all there is to migrating your existing applications to Macromedia Central, aside from the publishing process that I cover briefly at the end. The fun has only begun. Part of migrating your application to Macromedia Central requires taking advantage of all the added functionality built into the Central framework. This includes developing your application for online and offline use; standardizing your application's user interface to conform to the consistent look and feel throughout the Central environment; managing your application data with agents; and incorporating pods and notices, to name a few. Macromedia Central is a powerful medium to enhance and distribute your applications. The following section will give you an overview of the implementation of these new features into your application.

Developing for Online and Offline Use

One of the many advantages of using Central rather than a web browser or other medium is the ability to develop more intuitively for an occasionally connected platform. Macromedia Central caters to mobile users, allowing you to cache files and data for use when they're offline. Migrating your existing applications and incorporating this functionality gives end users an overall better user experience.

It is important to understand that users communicate their connection status to Central; Central cannot determine connection status directly. By selecting the lightning bolt in the Central toolbar users can toggle between online and offline mode.

Application.onNetworkChange

The Central shell calls the onNetworkChange(connected) function when the user changes the network connection status (from online to offline and back). Include any code that you want to execute in response to the status change in this function, such as toggling variables used to determine whether to use data from the Internet or from the cache:

function onNetworkChange(connected) 
{
     gOnline = connected;
     if (gOnline)
     {
          updateData();
     }
}

Shell.isConnected

In addition to the application (console/agent) function onNetworkChange, the isConnected function allows you to determine Central's connection status. The isConnected function returns a Boolean value representing the users' connection status: true if a connection is present and false if no connection is available.

Caching Data for Offline Use

As I wrote earlier, your ability to cache data for offline use is a large benefit of developing applications for Macromedia Central. This enables users of occasionally connected devices (laptops and PDAs) to access your application's data and functionality where live data is not available. For already parsed data, user preferences, and so forth, it's best to use the familiar shared objects. For other sources of data, there is an XML node you can add to your installation file, as well as a simple API that is implemented for this caching process.

The first method of caching files is through your Product XML Descriptor File (more about that at the end). Simply adding the following line caches the file when your application is installed:

<file src="http://www.myCompany.com/images/shared/product_logos/logo.jpg"/>

The second method is a built-in API:

gShell.addToLocalInternetCache("http://www.myCompany.com/logos/logo_1.jpg");

The first parameter is the URL of the file you want to cache. Two optional parameters include a Boolean value indicating whether to overwrite the file if it already exists in the cache. The next parameter is either a Date object or a number, specifying the date or how many days until the file expires in the cache.

Other methods include gShell.inLocalInternetCache(url), which returns a Boolean value reflecting the status of the file, representing whether or not it is in the user's local Internet cache; and removeFromLocalInternetCache(url), which removes the file from the user's local hard drive.

The default amount of space shared by all applications running in Central is 20 MB. When the application exceeds that amount, it asks the user to allow more space for local Internet files. If the user refuses, the file is not cached.

Incorporating the Macromedia Central Components

Why use Macromedia Central components? There are a couple of reasons. It is important to provide users with a common user interface when developing applications. A common user interface means a small learning curve because users are already familiar with how similar elements work in other applications.

Your application can take advantage of a myriad of components installed with Central without any additional overhead. Unique components built specifically for Central include AccordianTab, ExpandingPod, DialogBox, IconMenu, RoundIconButton, TextInputField, and four image-only components. Other components include: Calendar, CheckBox, ComboBox, DataGrid, IconButtom, ListBox, ProgressBar, PushButtom, RadioButtom, ScrollBar, and ScrollPane. Unlike Flash UI components, these cannot be skinned and the use of styles is not supported. Some components, however, contain additional functionalities and are customizable to some degree.

Macromedia strongly recommends using the components' default font settings, which are 10-point Verdana, text color #2B333C, and disabled text color #AAB3B3. However, you may customize text font and size. Some components, such as AccordianTab and DataGrid, include functionality for color changes to match the color of your application; other customizable areas include component dimensions.

Managing Your Data

Macromedia Central provides a framework to help simplify the management of data between your applications' elements. This functionality is provided in the form of agents and using the LCService and LCDataProvider APIs. Additional documentation about these implementations appears in the Macromedia Central SDK.

Agents

One optional component for your application is an agent. Agents provide an environment for your application, or multiple instances of your application, to communicate to a single data manager. An agent is a "headless SWF" (a SWF without any graphical elements) that processes tasks in the background, invisible to the user. Even when your application is not running, an agent can poll for data, monitor the connection, and so on. When developing your agent, keep in mind that users can disable them. Your product should work whether users disable agents or not.

LCService

To enhance the communication between your application elements, Central provides LCService as a more robust solution than the standard LocalConnection object. The enhanced server/client method calling is ideal for applications that have multiple parts. It allows the application, agent, and pods to communicate among one another more easily by facilitating the ability to define functions that be called from other application parts (for example, a pod calling a function in an agent). A typical implementation puts the server type functionality into your agent, while the corresponding clients are put into the application and pods. Below is a brief example:

// Interface.as
ITestInterface = new Object();
ITestInterface.name = "ITestInterface";
ITestInterface.interfaces = new Array();
ITestInterface.interfaces["Client"] = [];
ITestInterface.interfaces["Server"] = ["echo"];


// ServerAgent.as
#include "Interface.as"
function onActivate( agentManager, agentId, initialData ) 
     { 
          gAgentManager = agentManager;
          gTestService = Central.LCService.createServer( ITestInterface, this ); 
     }
function echo( echoString ) 
     {
          return echoString; 
     }


// ClientApp.as 
#include "Interface.as"
function onActivate( shell, appId, shellId, baseTabIndex, initialData ) 
     { 
          gShell = shell;
          gShellUID = String(appId) + "_" + String(shellId);
          gTestService = Central.LCService.createClient( ITestInterface, gShellUID, this );
          gTestService.echo("foobar"); 
     }
function echo_Result( echoString ) 
     {
          trace("echo_Result = " + echoString );
     }
Central.initApplication( this, this ); 

LCDataProvider

Similar to LCService, LCDataProvider provides a central location to store, manage, and access data. Based on the DataProvider object, LCDataProvider allows you to create a central location for the application and pods to access data. Creating the client and server halves of LCDataProvider is similar to using the LCService object, only you don't have to specify any methods:

// create the LCDataProvider Server
foodList_dp = Central.LCDataProvider.createServer("food_list"); 

// create an array
     var foods = ["corn", "chicken"];

// populate the LCDataProvider object
     foodList_dp.setData( foods );

     // ------

     // create the LCDataProvider Client
     foodList_dp = Central.LCDataProvider.createClient( this.fClientID, "food_list" ); 
     myComboBox.setDataProvider( foodList_dp );

Incorporating Pods and Notices into Your Application

Pods are small iterations of your application and notices advise users of important events. Use these enhancements to provide additional methods of interaction and feedback for users.

Pods

Pods are small extensions of an application that are housed in the Console. They are useful for displaying frequently updated data that users might want to view on the desktop without having to open the application window. Pods can also be designed as scaled-down versions of the host application. An example might be a chat application that handles private or one-on-one conversations through a pod, while the application itself hosts the chat room, user list, room list, and so on. Pods are created during installation according to the product.xml file or dynamically through the API. Pods can be spawned at installation time or can come into view dynamically through the API or user interface.

Notices

An application, pod, or agent running the background can generate notices, which are used to notify users of important events pertaining to a specific application:

notice = new Object();
notice.name = "Application Notice Event";
notice.description = "Click Launch, to open or switch to Application"; 
notice.engageString = "Launch";
notice.navigate = true; 
notice.alert = true;
gManager.addNotice(notice); 

Interaction with notices allows users to launch or switch to the corresponding application.